package thread;

//真实对象，代理对象实现同一个接口
//代理对象代理真实对象
//好处：代理对象可以帮真实对象做很多事情
//真实对象只需做自己的事情
public class StaticProxy {
    public static void main(String[] args) {
        WeddingCompany wed = new WeddingCompany(new You());
        wed.happyMarry();
    }

}
interface Marry{
    //久旱逢甘露、他乡遇故知、洞房花烛夜、金榜题名时
    void happyMarry();
}

//真实角色
class You implements Marry{

    @Override
    public void happyMarry() {
        System.out.println("洞房花烛夜");
    }
}


//代理角色
class WeddingCompany implements Marry{

    private Marry target;
    public WeddingCompany(Marry target){
        this.target = target;
    }

    @Override
    public void happyMarry() {
        before();
        this.target.happyMarry();
        after();
    }

    private void after() {
        System.out.println("婚后");
    }

    private void before() {
        System.out.println("婚前");
    }
}
